repo: Add unconfigured-state to remote config options
authorColin Walters <walters@verbum.org>
Thu, 8 Dec 2016 19:20:19 +0000 (14:20 -0500)
committerAtomic Bot <atomic-devel@projectatomic.io>
Fri, 9 Dec 2016 17:46:54 +0000 (17:46 +0000)
This is a migration from the origin version.  It's
nicer to have it in the remote, since that's what one
needs to change.  Then tools don't need to mess with
the origin file.o

In fact in this scenario one can keep the "media source" like
`file:///install/repo` or whatever, since conceptually that's where it
came from.  We're just providing a better error.

Closes: https://github.com/ostreedev/ostree/issues/626
Closes: #627
Approved by: jlebon

man/ostree.repo-config.xml
src/libostree/ostree-repo-pull.c
src/libostree/ostree-sysroot-upgrader.c
tests/pull-test.sh

index 5e0383a6e839df00cbf954e0020b3d742ce908fe..b4c276dfc234c45122f2e0809fb44b554f878b32 100644 (file)
@@ -179,6 +179,11 @@ Boston, MA 02111-1307, USA.
         <term><varname>tls-ca-path</varname></term>
         <listitem><para>Path to file containing trusted anchors instead of the system CA database.</para></listitem>
       </varlistentry>
+
+      <varlistentry>
+        <term><varname>unconfigured-state</varname></term>
+        <listitem><para>If set, pulls from this remote will fail with the configured text.  This is intended for OS vendors which have a subscription process to access content.</para></listitem>
+      </varlistentry>
     </variablelist>
 
   </refsect1>
index 46724b85268f08536d178c8a21adcd835c519e78..9c99dc4fbde26bac2f333988402d7e95e16f2774 100644 (file)
@@ -2458,6 +2458,8 @@ ostree_repo_pull_with_options (OstreeRepo             *self,
     }
   else
     {
+      g_autofree char *unconfigured_state = NULL;
+
       pull_data->remote_name = g_strdup (remote_name_or_baseurl);
 
       /* Fetch GPG verification settings from remote if it wasn't already
@@ -2471,6 +2473,22 @@ ostree_repo_pull_with_options (OstreeRepo             *self,
         if (!ostree_repo_remote_get_gpg_verify_summary (self, pull_data->remote_name,
                                                         &pull_data->gpg_verify_summary, error))
           goto out;
+
+      /* NOTE: If changing this, see the matching implementation in
+       * ostree-sysroot-upgrader.c
+       */
+      if (!ostree_repo_get_remote_option (self, pull_data->remote_name,
+                                          "unconfigured-state", NULL,
+                                          &unconfigured_state,
+                                          error))
+        goto out;
+
+      if (unconfigured_state)
+        {
+          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                       "remote unconfigured-state: %s", unconfigured_state);
+          goto out;
+        }
     }
 
   pull_data->phase = OSTREE_PULL_PHASE_FETCHING_REFS;
index 447bd82bed74ec524a2e01461c090c93876cea75..daf2445c1177cf08d9a2e10ab225fc52000bf1c0 100644 (file)
@@ -77,7 +77,9 @@ parse_refspec (OstreeSysrootUpgrader  *self,
 
   if ((self->flags & OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED) == 0)
     {
-      /* If explicit action by the OS creator is requried to upgrade, print their text as an error */
+      /* If explicit action by the OS creator is requried to upgrade, print their text as an error.
+       * NOTE: If changing this, see the matching implementation in ostree-repo-pull.c.
+       */
       unconfigured_state = g_key_file_get_string (self->origin, "origin", "unconfigured-state", NULL);
       if (unconfigured_state)
         {
index 408d05392579f2860f46520734ce415874e398e5..56258b6c688b385af47f577b8b7055bfb1445eaf 100755 (executable)
@@ -35,7 +35,7 @@ function verify_initial_contents() {
     assert_file_has_content baz/cow '^moo$'
 }
 
-echo "1..13"
+echo "1..14"
 
 # Try both syntaxes
 repo_init
@@ -249,3 +249,12 @@ assert_file_has_content baz/cow "further modified file for static deltas"
 assert_not_has_file baz/saucer
 
 echo "ok static delta 2"
+
+cd ${test_tmpdir}
+${CMD_PREFIX} ostree --repo=repo remote add --set=gpg-verify=false --set=unconfigured-state="Access to ExampleOS requires ONE BILLION DOLLARS." origin-subscription file://$(pwd)/ostree-srv/gnomerepo
+if ${CMD_PREFIX} ostree --repo=repo pull origin-subscription main 2>err.txt; then
+    assert_not_reached "pull unexpectedly succeeded?"
+fi
+assert_file_has_content err.txt "ONE BILLION DOLLARS"
+
+echo "ok unconfigured"